package com.ewzj.bigdata.mvp.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewzj.bigdata.R;
import com.ewzj.bigdata.app.constants.AppConstants;
import com.ewzj.bigdata.mvp.model.entity.resbean.CollectBean;
import com.ewzj.bigdata.mvp.ui.activity.CollectListActivity;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Author:zhangjing
 * Time:2018/3/14  下午2:08
 * Name: this is CollectAdapter
 * Email:zhangjingworkmol@163.com
 */

public class CollectAdapter extends BaseQuickAdapter<CollectBean,BaseViewHolder>{
    private ImageLoader imageLoader;
    public CollectAdapter( @Nullable List<CollectBean> data) {
        super(R.layout.item_collect, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CollectBean item) {
        if (imageLoader==null){
            imageLoader= ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
        if (!TextUtils.isEmpty(item.getThumb())){
            imageLoader.loadImage(mContext, ImageConfigImpl.builder().url(item.getThumb())
                    .transformation(new CircleCrop())
                    .imageView(helper.<ImageView>getView(R.id.iv_collect))
                    .build());
        }
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, CollectListActivity.class);
                intent.putExtra(AppConstants.EXTRA_DATA,item);
                ArmsUtils.startActivity(intent);
            }
        });
        helper.<TextView>getView(R.id.tv_collectname).setText(item.getTitle());
        helper.<TextView>getView(R.id.tv_num).setText(item.getNum()+"");
        helper.<TextView>getView(R.id.tv_timeinfo).setText("最近访问："+item.getTime()+"");
        helper.addOnClickListener(R.id.iv_edit);
        helper.addOnClickListener(R.id.iv_del);
    }
}
